package com.cloudeye.logtest.com.cloudeye.logtest.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.GenericApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * Created by lafangyuan on 2020/10/22.
 */
public class TestRunListener implements GenericApplicationListener {

    public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 100;

    private static final Logger logger = LoggerFactory.getLogger(TestRunListener.class);
    SpringApplication application = null;
    String[] args = null;

    @Override
    public boolean supportsEventType(ResolvableType eventType) {
        logger.info("eventType:{}",eventType.toString());
        return true;
    }
    @Override
    public int getOrder() {
        return DEFAULT_ORDER;
    }
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
//        logger.info("TestRun,eventType is:{}",event.toString());
        if(event instanceof ApplicationReadyEvent){
            ApplicationReadyEvent ase = (ApplicationReadyEvent) event;
            ConfigurableEnvironment environment = ase.getApplicationContext().getEnvironment();
            String sqlDb = ase.getApplicationContext().getEnvironment().getProperty("sql.db");
            logger.info("sql----db:{}",sqlDb);
            logger.info("sql----mq:{}",ase.getApplicationContext().getEnvironment().getProperty("mq"));
            logger.info("sql----dd:{}",ase.getApplicationContext().getEnvironment().getProperty("dd"));
        }
    }
}
